package com.hmall.order.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TTlMessageConfig {

    /**
     * 创建一个队列
     *
     * @return {@link Queue}
     */
    @Bean
    public Queue ttlQueue(){
        return QueueBuilder.durable("ttl.queue")
                .deadLetterExchange("dl.ttl.direct") //指定死信交换机
                .deadLetterRoutingKey("dl")
                .build();
    }

    /**
     * 创建一个交换机
     *
     * @return {@link DirectExchange}
     */
    @Bean
    public DirectExchange ttlExchange(){
        return new DirectExchange("ttl.direct");
    }

    @Bean
    public Binding ttlBinding() {
        return BindingBuilder.bind(ttlQueue()).to(ttlExchange()).with("ttl");
    }

}
